package com.idemon.springboot.dao.impl;

import com.idemon.springboot.dao.IUserinfoDAO;
import com.idemon.springboot.po.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@Repository
public class UserinfoDAO implements IUserinfoDAO {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Userinfo> getAll() {
        return jdbcTemplate.query("select * from userinfo", new RowMapper<Userinfo>() {
            @Override
            public Userinfo mapRow(ResultSet resultSet, int i) throws SQLException {
                int j = 1;
                Userinfo userinfo = new Userinfo();
                userinfo.setId(resultSet.getInt(j++));
                userinfo.setName(resultSet.getString(j++));
                userinfo.setAge(resultSet.getInt(j++));
                return userinfo;
            }
        });
    }
}
